package com.neusoft.nep.common;

import com.neusoft.nep.supervise.entity.User;

/**
 * 会话管理器 - 确保数据在不同页面间正确传递和绑定
 */
public class SessionManager {
    private static String currentUserId = null;
    private static User currentUser = null;
    private static String currentGridId = null;
    private static String currentSubmissionId = null;

    // 用户相关的会话管理
    public static void setCurrentUserId(String userId) {
        currentUserId = userId;
    }

    public static String getCurrentUserId() {
        return currentUserId;
    }

    public static void setCurrentUser(User user) {
        currentUser = user;
    }

    public static User getCurrentUser() {
        return currentUser;
    }

    // Grid相关的会话管理
    public static void setCurrentGridId(String gridId) {
        currentGridId = gridId;
    }

    public static String getCurrentGridId() {
        return currentGridId;
    }

    public static void clearCurrentGridId() {
        currentGridId = null;
    }

    // Submission相关的会话管理
    public static void setCurrentSubmissionId(String submissionId) {
        currentSubmissionId = submissionId;
    }

    public static String getCurrentSubmissionId() {
        return currentSubmissionId;
    }

    public static void clearCurrentSubmissionId() {
        currentSubmissionId = null;
    }

    // 清理所有会话数据
    public static void clearAllSession() {
        currentUserId = null;
        currentUser = null;
        currentGridId = null;
        currentSubmissionId = null;
    }

    // 检查会话完整性
    public static boolean isSessionComplete() {
        return currentUserId != null && currentUser != null;
    }

    // 调试方法：输出当前会话状态
    public static void printSessionStatus() {
        System.out.println("=== 会话状态 ===");
        System.out.println("当前用户ID: " + currentUserId);
        System.out.println("当前用户: " + (currentUser != null ? currentUser.getUserName() : "null"));
        System.out.println("当前网格ID: " + currentGridId);
        System.out.println("当前提交ID: " + currentSubmissionId);
        System.out.println("===============");
    }
}